package com.clayecloud.common.admin.services.Impl;


import com.clayecloud.common.admin.services.ReportForRepairService;
import com.clayecloud.common.entity.ReportForRepair;
import com.clayecloud.common.mappers.ProcessTackingMapper;
import com.clayecloud.common.mappers.ReportForRepairMapper;
import com.clayecloud.common.utils.MessageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("AdminReportForRepairServiceImpl")
public class ReportForRepairServiceImpl implements ReportForRepairService {

    @Resource
    ReportForRepairMapper reportForRepairMapper;

    @Resource
    ProcessTackingMapper processTackingMapper;

    @Override
    public MessageUtil insertSelective(ReportForRepair record) {
        return reportForRepairMapper.insertSelective(record) > 0 ? MessageUtil.success("增加成功"):MessageUtil.fail("增加失败，请联系系统管理员");
    }

    @Override
    public MessageUtil deleteByPrimaryKey(Long rrId) {
        return reportForRepairMapper.deleteByPrimaryKey(rrId) > 0 && processTackingMapper.deleteBytrackId(rrId) > 0 ? MessageUtil.success("删除成功"):MessageUtil.fail("删除失败，请联系系统管理员");
    }

    @Override
    public MessageUtil updateByPrimaryKeySelective(ReportForRepair record) {
        return reportForRepairMapper.updateByPrimaryKeySelective(record) > 0 ? MessageUtil.success("修改成功"):MessageUtil.fail("修改失败，请联系系统管理员");
    }

    @Override
    public MessageUtil<List<ReportForRepair>> selectAll(Integer size, Integer page) {
        PageHelper.startPage(page,size);
        List<ReportForRepair> reportForRepairs = reportForRepairMapper.selectAll();
        PageInfo pageInfo = new PageInfo(reportForRepairs);
        Map result = new HashMap();
        result.put("list",reportForRepairs);
        result.put("total",pageInfo.getTotal());
        return MessageUtil.success("查询成功").add(result);
    }
}
